<!--
 * @Author: zhouwr 1551541860@qq.com
 * @Date: 2024-02-17 19:50:23
 * @LastEditors: zhouwr 1551541860@qq.com
 * @LastEditTime: 2024-02-28 22:05:31
 * @FilePath: /jeecgboot-vue3/src/views/activiti/procdef/ActProcessDefList.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="processKey">
              <template #label><span title="流程key">流程key</span></template>
              <a-input placeholder="请输入流程key" v-model:value="queryParam.processKey" />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="category">
              <template #label><span title="流程类别">流程类别</span></template>
              <j-dict-select-tag v-model:value="queryParam.category" dictCode="act_model_type" placeholder="请选择流程类别" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :lg="6">
              <a-form-item name="version">
                <template #label><span title="流程版本">流程版本</span></template>
                <a-input placeholder="请输入流程版本" v-model:value="queryParam.version" />
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="isSuspended">
                <template #label><span title="是否已暂停">状态</span></template>
                <j-dict-select-tag v-model:value="queryParam.isSuspended" dictCode="proccesDefState" placeholder="请选择" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <a @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
                </a>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增部署</a-button>
      </template>
      <!-- 挂起状态 -->
      <template #procdefState="{ text }">
        <a-tag v-if="text === 0" color="green">激活</a-tag>
        <a-tag v-if="text === 1" color="pink">挂起</a-tag>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
      <template #bodyCell="{ column, record, index, text }"> </template>
    </BasicTable>
    <!-- 表单区域 -->
    <ActProcessDefAddModal ref="registerAddModal" @success="handleSuccess" />
    <ActProcessDefStartModal ref="registerStartModal" @success="handleSuccess" />
    <ActProcessDefConfig @register="registerConfigModal" @success="handleSuccess" />
    <ActProcessDefResourceModal @register="registerResourceModal" />
  </div>
</template>

<script lang="ts" name="procdef-actProcessDef" setup>
  import { ref, reactive } from 'vue'
  import { BasicTable, TableAction } from '/@/components/Table'
  import { useListPage } from '/@/hooks/system/useListPage'
  import { columns } from './ActProcessDef.data'
  import { listPage, deleteOne, updateState, convertToModel } from './ActProcessDef.api'
  import { useUserStore } from '/@/store/modules/user'
  import { usePermission } from '/@/hooks/web/usePermission'
  import { useModal } from '@/components/Modal'
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue'
  import ActProcessDefAddModal from './components/ActProcessDefAddModal.vue'
  import ActProcessDefStartModal from './components/ActProcessDefStartModal.vue'
  import ActProcessDefConfig from './components/actProcessDefConfig/ConfigModal.vue'
  import ActProcessDefResourceModal from '@/views/activiti/procdef/components/ActProcessDefResourceModal.vue'
  import { useGo } from '/@/hooks/web/usePage'

  const { hasPermission } = usePermission()

  const formRef = ref()
  const queryParam = reactive<any>({})
  const toggleSearchStatus = ref<boolean>(false)
  const registerAddModal = ref()
  const registerStartModal = ref()
  const userStore = useUserStore()
  const go = useGo()

  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '流程部署',
      api: listPage,
      columns,
      canResize: false,
      useSearchForm: false,
      actionColumn: {
        width: 280,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam)
      },
    },
  })
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext

  const labelCol = reactive({
    xs: 24,
    sm: 4,
    xl: 6,
    xxl: 4,
  })
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  })

  // 注册业务配置Model
  const [registerConfigModal, { openModal: openConfigModal }] = useModal()

  // 流程资源：流程图、Bpmn
  const [registerResourceModal, { openModal: openResourceModal }] = useModal()

  /**
   * 新增事件
   */
  function handleAdd() {
    registerAddModal.value.disableSubmit = false
    registerAddModal.value.add()
  }

  /**
   * 业务配置
   * @param record
   */
  function handleBusinessConfig(record: Recordable) {
    openConfigModal(true, {
      processDefId: record.id,
    })
  }

  /**
   * 激活|挂起事件
   */
  function handleUpdateState(record: Recordable) {
    const state = record.isSuspended == 0 ? 'suspend' : 'active'
    updateState({ procDefId: record.id, state: state }, handleSuccess)
  }

  function handleConvertToModel(record: Recordable) {
    convertToModel({ procDefId: record.id })
  }

  /**
   * 流程图
   */
  function handleResourceImage(record: Recordable) {
    openResourceModal(true, { processDefId: record.id })
  }

  function handleStartProcess(record: Recordable) {
    registerStartModal.value.start(record)
  }

  function handleVersionManage(record: Recordable) {
    go('/activiti/procdef/history/' + record.processKey)
  }

  function handleInstanceManage(record: Recordable) {
    go('/activiti/procdef/instance/' + record.processKey)
  }

  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.deploymentId }, handleSuccess)
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    ;(selectedRowKeys.value = []) && reload()
  }

  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '启动',
        onClick: handleStartProcess.bind(null, record),
        ifShow: () => {
          // return hasPermission('act:procdef:start')
          return !record.isSuspended
        },
      },
      {
        label: '业务配置',
        onClick: handleBusinessConfig.bind(null, record),
      },
      {
        label: '流程图',
        onClick: handleResourceImage.bind(null, record),
      },
    ]
  }

  /**
   * 下拉操作栏
   */
  function getDropDownAction(record) {
    return [
      {
        label: record.isSuspended == 0 ? '挂起' : '激活',
        popConfirm: {
          title: '是否确认' + (record.isSuspended == 0 ? '挂起' : '激活'),
          confirm: handleUpdateState.bind(null, record),
          placement: 'topLeft',
        },
        ifShow: () => {
          return hasPermission('act:procdef:updateState')
        },
      },
      {
        label: '版本管理',
        onClick: handleVersionManage.bind(null, record),
      },
      {
        label: '实例管理',
        onClick: handleInstanceManage.bind(null, record),
      },
      {
        label: '转换为模型',
        popConfirm: {
          title: '是否确认转换为模型',
          confirm: handleConvertToModel.bind(null, record),
          placement: 'topLeft',
        },
        ifShow: () => {
          return hasPermission('act:procdef:convertToModel')
        },
      },
      {
        label: '删除',
        popConfirm: {
          title: '是否确认删除',
          confirm: handleDelete.bind(null, record),
          placement: 'topLeft',
        },
      },
    ]
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload()
  }

  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields()
    selectedRowKeys.value = []
    //刷新数据
    reload()
  }
</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;

    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }

    .query-group-cust {
      min-width: 100px !important;
    }

    .query-group-split-cust {
      width: 30px;
      display: inline-block;
      text-align: center;
    }
  }
</style>
./components/actProcessDefConfig/ConfigModal.vue
